cmake_minimum_required(VERSION 3.5)

project(mnsui VERSION 0.1)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

### set Qt6_DIR to your Qt installation path
set(Qt6_DIR $ENV{Qt6_DIR})
message(STATUS "The value of Qt6_DIR is: $ENV{Qt6_DIR}")
# set(Qt6_DIR /Users/stonego/Qt/6.6.2/macos/lib/cmake/Qt6)

### set MU to your application installation path
# set (MU /usr/local)
#set (MU /ssd1/mycat/usr)
# set (MU /Users/stonego/usr)
message(STATUS "The value of TO_INSTALL_PATH is: $ENV{TO_INSTALL_PATH}")

set (MU $ENV{TO_INSTALL_PATH})

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MU}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MU}/bin)

set(MY_INSTALL_LIBDIR, ${MU}/lib)
set(MY_INSTALL_BINDIR, ${MU}/bin)

find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Charts)

IF (CMAKE_SYSTEM_NAME MATCHES "Linux") 
    MESSAGE(STATUS "current platform: Linux ")
    add_definitions(-D_LINUX_)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Windows") 
    MESSAGE(STATUS "current platform: Windows") 
    add_definitions(-D_WINDOWS_)
ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Darwin") 
    MESSAGE(STATUS "current platform: Mac OS X") 
    add_definitions(-D_MACOS_)
ELSE () 
    MESSAGE(STATUS "other platform: ${CMAKE_SYSTEM_NAME}") 
    add_definitions(-D_OTHER_)
ENDIF (CMAKE_SYSTEM_NAME MATCHES "Linux") 

qt_standard_project_setup()

include(GNUInstallDirs)


include_directories(
  include
)

link_directories(
  /usr/local/lib
  /usr/lib
  /lib
  ${MU}/lib
)



#configuration types
SET(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
IF(DEFINED CMAKE_BUILD_TYPE AND CMAKE_VERSION VERSION_GREATER "2.8")
  SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
ENDIF()

set(SOURCE_CODE
  src/datachart.h
  src/mainwidget.h
  src/ticker.h
  src/udps.h
  src/datachart.cpp
  src/main.cpp
  src/mainwidget.cpp
  src/ticker.c
  src/udps.cpp
  src/dataview.h
  src/dataview.cpp
  src/data.cpp
  src/data.h
  src/dirsblocks.h
  src/dirsblocks.cpp
)


IF (CMAKE_BUILD_TYPE MATCHES Debug)
  set(MNSUI mnsuid)
  qt_add_executable(${MNSUI}
    ${SOURCE_CODE}
  )

  message("Debug build mnsuid")
  set(CMAKE_C_FLAGS_DEBUG "-Wall -g")
  set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g")
  set(CMAKE_DEBUG_POSTFIX "d")
  add_definitions(-DSTONE_DEBUG=1)

  set_target_properties(${MNSUI} PROPERTIES
      MACOSX_BUNDLE TRUE
      WIN32_EXECUTABLE TRUE
  )

  target_link_libraries(${MNSUI} PRIVATE
      Qt6::Core
      Qt6::Gui
      Qt6::Widgets
      Qt6::Charts
  )

  target_link_libraries(${MNSUI} PRIVATE mttraded)

  install(TARGETS ${MNSUI}
      BUNDLE DESTINATION .
      LIBRARY DESTINATION ${MY_INSTALL_LIBDIR}
      RUNTIME DESTINATION ${MY_INSTALL_BINDIR}
  )
ENDIF ()


IF (CMAKE_BUILD_TYPE MATCHES Release)
  set(MNSUI mnsui)

  qt_add_executable(${MNSUI}
    ${SOURCE_CODE}
  )

  message("Release build mnsui")
  set(CMAKE_C_FLAGS "-Wall -O2")
  set(CMAKE_CXX_FLAGS "-Wall -O2")

  add_definitions(-DSTONE_DEBUG=0)

  set_target_properties(${MNSUI} PROPERTIES
      MACOSX_BUNDLE TRUE
      WIN32_EXECUTABLE TRUE
  )

  target_link_libraries(${MNSUI} PRIVATE
      Qt6::Core
      Qt6::Gui
      Qt6::Widgets
      Qt6::Charts
  )

  target_link_libraries(${MNSUI} PRIVATE mttrade)

  install(TARGETS ${MNSUI}
      BUNDLE DESTINATION .
      LIBRARY DESTINATION ${MY_INSTALL_LIBDIR}
      RUNTIME DESTINATION ${MY_INSTALL_BINDIR}
  )
ENDIF ()  # Release Version


if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(mnsui)
endif()


add_executable(fixm4s src/fixm4s.c)
install(TARGETS fixm4s
  BUNDLE DESTINATION .
  LIBRARY DESTINATION ${MY_INSTALL_LIBDIR}
  RUNTIME DESTINATION ${MY_INSTALL_BINDIR}
)

add_executable(hex-head src/hex.c)

